Conditions | 1 |
Paths | 1 |
Total Lines | 202 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
10 | jQuery(document).ready(function () { |
||
11 | /** |
||
12 | * Enable select2 |
||
13 | */ |
||
14 | jQuery( '.select2' ).select2(); |
||
15 | |||
16 | // Start Jetpack. |
||
17 | BulkWP.jetpack(); |
||
18 | |||
19 | BulkWP.enableHelpTooltips( jQuery( '.bd-help' ) ); |
||
20 | |||
21 | jQuery( '.user_restrict_to_no_posts_filter' ).change( function() { |
||
22 | var $this = jQuery(this), |
||
23 | filterEnabled = $this.is( ':checked' ), |
||
24 | $filterItems = $this.parents( 'table' ).children().find( '.user_restrict_to_no_posts_filter_items' ); |
||
25 | |||
26 | if ( filterEnabled ) { |
||
27 | $filterItems.removeClass( 'visually-hidden' ); |
||
28 | } else { |
||
29 | $filterItems.addClass( 'visually-hidden' ); |
||
30 | } |
||
31 | } ); |
||
32 | |||
33 | /** |
||
34 | * Enable Postbox handling |
||
35 | */ |
||
36 | postboxes.add_postbox_toggles(pagenow); |
||
37 | |||
38 | /** |
||
39 | * Toggle the date restrict fields |
||
40 | */ |
||
41 | function toggle_date_restrict(el) { |
||
42 | if (jQuery("#smbd" + el + "_restrict").is(":checked")) { |
||
43 | jQuery("#smbd" + el + "_op").removeAttr('disabled'); |
||
44 | jQuery("#smbd" + el + "_days").removeAttr('disabled'); |
||
45 | } else { |
||
46 | jQuery("#smbd" + el + "_op").attr('disabled', 'true'); |
||
47 | jQuery("#smbd" + el + "_days").attr('disabled', 'true'); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Toggle limit restrict fields |
||
53 | */ |
||
54 | function toggle_limit_restrict(el) { |
||
55 | if (jQuery("#smbd" + el + "_limit").is(":checked")) { |
||
56 | jQuery("#smbd" + el + "_limit_to").removeAttr('disabled'); |
||
57 | } else { |
||
58 | jQuery("#smbd" + el + "_limit_to").attr('disabled', 'true'); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Toggle user login restrict fields |
||
64 | */ |
||
65 | function toggle_login_restrict(el) { |
||
66 | if (jQuery("#smbd" + el + "_login_restrict").is(":checked")) { |
||
67 | jQuery("#smbd" + el + "_login_days").removeAttr('disabled'); |
||
68 | } else { |
||
69 | jQuery("#smbd" + el + "_login_days").attr('disabled', 'true'); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Toggle user registered restrict fields |
||
75 | */ |
||
76 | function toggle_registered_restrict(el) { |
||
77 | if (jQuery("#smbd" + el + "_registered_restrict").is(":checked")) { |
||
78 | jQuery("#smbd" + el + "_registered_days").removeAttr('disabled'); |
||
79 | } else { |
||
80 | jQuery("#smbd" + el + "_registered_days").attr('disabled', 'true'); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Toggle Post type dropdown. |
||
86 | */ |
||
87 | function toggle_post_type_dropdown( el ) { |
||
88 | // TODO: Check why the element is not toggling even when display:none is added by JS. |
||
89 | if ( jQuery( "#smbd" + el + "_no_posts" ).is( ":checked" ) ) { |
||
90 | jQuery( "tr#smbd" + el + "-post-type-dropdown" ).show(); |
||
91 | } else { |
||
92 | jQuery( "tr#smbd" + el + "-post-type-dropdown" ).hide(); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | // hide all terms |
||
97 | function hideAllTerms() { |
||
98 | jQuery('table.terms').hide(); |
||
99 | jQuery('input.terms').attr('checked', false); |
||
100 | } |
||
101 | // call it for the first time |
||
102 | hideAllTerms(); |
||
103 | |||
104 | // taxonomy click handling |
||
105 | jQuery('.custom-tax').change(function () { |
||
106 | var $this = jQuery(this), |
||
107 | $tax = $this.val(), |
||
108 | $terms = jQuery('table.terms_' + $tax); |
||
109 | |||
110 | if ($this.is(':checked')) { |
||
111 | hideAllTerms(); |
||
112 | $terms.show('slow'); |
||
113 | } |
||
114 | }); |
||
115 | |||
116 | // date time picker |
||
117 | jQuery.each(BulkWP.dt_iterators, function (index, value) { |
||
118 | // invoke the date time picker |
||
119 | jQuery('#smbd' + value + '_cron_start').datetimepicker({ |
||
120 | timeFormat: 'HH:mm:ss' |
||
121 | }); |
||
122 | |||
123 | jQuery('#smbd' + value + '_restrict').change(function () { |
||
124 | toggle_date_restrict(value); |
||
125 | }); |
||
126 | |||
127 | jQuery('#smbd' + value + '_limit').change(function () { |
||
128 | toggle_limit_restrict(value); |
||
129 | }); |
||
130 | |||
131 | jQuery('#smbd' + value + '_login_restrict').change(function () { |
||
132 | toggle_login_restrict(value); |
||
133 | }); |
||
134 | |||
135 | jQuery('#smbd' + value + '_registered_restrict').change(function () { |
||
136 | toggle_registered_restrict(value); |
||
137 | }); |
||
138 | |||
139 | jQuery( '#smbd' + value + '_no_posts' ).change( function () { |
||
140 | toggle_post_type_dropdown( value ); |
||
141 | }); |
||
142 | }); |
||
143 | |||
144 | jQuery.each( BulkWP.pro_iterators, function ( index, value) { |
||
145 | jQuery('.bd-' + value.replace( '_', '-' ) + '-pro').hide(); |
||
146 | jQuery('#smbd_' + value + '_cron_freq, #smbd_' + value + '_cron_start, #smbd_' + value + '_cron').removeAttr('disabled'); |
||
147 | } ); |
||
148 | |||
149 | // Validate user action |
||
150 | jQuery('button[name="bd_action"]').click(function () { |
||
151 | var currentButton = jQuery(this).val(), |
||
152 | valid = false, |
||
153 | msg_key = "deletePostsWarning", |
||
154 | error_key = "selectPostOption"; |
||
155 | |||
156 | if (currentButton in BulkWP.validators) { |
||
157 | valid = BulkWP[BulkWP.validators[currentButton]](this); |
||
158 | } else { |
||
159 | if (jQuery(this).parent().prev().children('table').find(":checkbox:checked[value!='true']").size() > 0) { // monstrous selector |
||
160 | valid = true; |
||
161 | } |
||
162 | } |
||
163 | |||
164 | if (valid) { |
||
165 | if (currentButton in BulkWP.pre_action_msg) { |
||
166 | msg_key = BulkWP.pre_action_msg[currentButton]; |
||
167 | } |
||
168 | |||
169 | return confirm(BulkWP.msg[msg_key]); |
||
170 | } else { |
||
171 | if (currentButton in BulkWP.error_msg) { |
||
172 | error_key = BulkWP.error_msg[currentButton]; |
||
173 | } |
||
174 | |||
175 | alert(BulkWP.msg[error_key]); |
||
176 | } |
||
177 | |||
178 | return false; |
||
179 | }); |
||
180 | |||
181 | /** |
||
182 | * Validation functions |
||
183 | */ |
||
184 | BulkWP.noValidation = function() { |
||
185 | return true; |
||
186 | }; |
||
187 | |||
188 | BulkWP.validateSelect2 = function(that) { |
||
189 | if (null !== jQuery(that).parent().prev().children().find(".select2[multiple]").val()) { |
||
190 | return true; |
||
191 | } else { |
||
192 | return false; |
||
193 | } |
||
194 | }; |
||
195 | |||
196 | BulkWP.validateUrl = function(that) { |
||
197 | if (jQuery(that).parent().prev().children('table').find("textarea").val() !== '') { |
||
198 | return true; |
||
199 | } else { |
||
200 | return false; |
||
201 | } |
||
202 | }; |
||
203 | |||
204 | BulkWP.validateUserMeta = function() { |
||
205 | if (jQuery('#smbd_u_meta_value').val() !== '') { |
||
206 | return true; |
||
207 | } else { |
||
208 | return false; |
||
209 | } |
||
210 | }; |
||
211 | }); |
||
212 | |||
261 |